package com.rw.tool.test.exception.extra;

import com.rw.tool.util.expression.element.Calculation;
import com.rw.tool.util.expression.exception.SignException;

import java.util.ArrayList;
import java.util.List;

public class DiceCalculation extends Calculation {
    /**
     * 骰子符号
     */
    public static final Calculation DICE = new DiceCalculation(0, "D", "d");

    protected DiceCalculation(int priority, String... sign) {
        super(priority, sign);
    }

    /**
     * 根据字符串解析出对应的计算符号
     */
    public static Calculation of(String sign) {
        List<Calculation> values = new ArrayList<>(Calculation.getCalculationValues());
        values.add(DiceCalculation.DICE);

        return values.stream()
                .filter(value -> value.getSign().contains(sign))
                .findAny()
                .orElseThrow(() -> new SignException(sign));
    }
}
